package com.zyark.web.controller;

import com.zyark.domain.VisitorInfo;
import com.zyark.service.VisitorInfoService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;

/**
 * Created by ron on 17-8-31.
 */
@Controller
@RequestMapping(value = "client")
public class ClientController {

    @Resource
    VisitorInfoService visitorInfoService;

    @RequestMapping(value = "list",method = RequestMethod.GET)
    @ResponseBody
    public Object getList(@RequestParam(value = "pageNumber",required = false)Integer pageNumber,
                          @RequestParam(value = "pageSize",required = false)Integer pageSize){
        if (pageNumber == null){
            pageNumber = 1;
        }
        if (pageSize == null){
            pageSize = 10;
        }
        return visitorInfoService.selectPageV2(pageNumber,pageSize);
    }

    @RequestMapping(value = "query/{key}",method = RequestMethod.GET)
    @ResponseBody
    public Object getQueryList(@PathVariable String key,@RequestParam(value = "pageNumber",required = false)Integer pageNumber,
                               @RequestParam(value = "pageSize",required = false)Integer pageSize){
        if (pageNumber == null){
            pageNumber = 1;
        }
        if (pageSize == null){
            pageSize = 10;
        }
        Example example = new Example(VisitorInfo.class);
        example.or().andLike("name","%" + key +"%");
        return visitorInfoService.selectPageByExampleV2(example,pageNumber,pageSize);
    }
}
